﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading;
using System.Diagnostics;

namespace NetworkSimulator
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                //Topology.instance();
                Thread.CurrentThread.Priority = ThreadPriority.Highest;
                RequestDispatcher reqDpchr = RequestDispatcher.instance();
                Console.WriteLine("NETWORK SIMULATOR");
                Console.WriteLine();
                Console.WriteLine("Total request: " + reqDpchr.NumOfRequest);
                Console.WriteLine("Accepted request: 0");
                Console.WriteLine("Rejected request: 0");
                Console.WriteLine("Reroute request: 0");
                Console.WriteLine("Rerouted request: 0");
                Console.WriteLine("");
                //Console.WriteLine("===========================================");
                //Console.WriteLine(" FUNCTION ");
                //Console.WriteLine("===========================================");
                //Console.WriteLine("1. Break a link");
                //Console.WriteLine();
                //Console.Write("Choose function: ");
                Thread thread = new Thread(new ThreadStart(showServed));
                thread.Start();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.StackTrace);
            }
            Console.ReadKey();
        }

        static void showServed()
        {
            int accept = 0;
            int reject = 0;
            int reroute = 0;
            int rerouted = 0;
            while (true)
            {
                if (accept != Node.acceptedCount)
                {
                    accept = Node.acceptedCount;
                    Console.SetCursorPosition(0, 3);
                    Console.WriteLine("Accepted request: " + Node.acceptedCount);
                }
                if (reject != Node.rejectedCount)
                {
                    reject = Node.rejectedCount;
                    Console.SetCursorPosition(0, 4);
                    Console.WriteLine("Rejected request: " + Node.rejectedCount);
                }
                if (reroute != Node.rerouteCount)
                {
                    reroute = Node.rerouteCount;
                    Console.SetCursorPosition(0, 5);
                    Console.WriteLine("Reroute request: " + Node.rerouteCount);
                }
                if (reroute != Node.reroutedCount)
                {
                    rerouted = Node.reroutedCount;
                    Console.SetCursorPosition(0, 6);
                    Console.WriteLine("Rerouted request: " + Node.reroutedCount);
                }
                //Console.SetCursorPosition(17, 12);
                Thread.Sleep(100);
            }
        }
    }
}
